{
 "metadata": {
  "name": "",
  "signature": "sha256:cd047523fa354e96f6d44d513f41b6f3172d5f83688931e65595efb85afa9365"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import os\n",
      "import pandas as pd\n",
      "import numpy as np"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 3
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "train_path = r\"/media/root/515e7d3a-49ac-40be-ba58-fef9702d123c/work_record/digit_recognizer/digit-recognizer/digit-recognizer/1216/digit/train\"\n",
      "val_path = r\"/media/root/515e7d3a-49ac-40be-ba58-fef9702d123c/work_record/digit_recognizer/digit-recognizer/digit-recognizer/1216/digit/val\"\n",
      "label = np.loadtxt('label.csv')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 11
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "train_list = os.listdir(train_path)\n",
      "train_label = []\n",
      "train_img = []\n",
      "num = len(train_list)\n",
      "for i in range(num):\n",
      "    prefix, type_ = os.path.splitext(train_list[i])\n",
      "    if type_ == \".jpg\":\n",
      "        index = int(prefix)\n",
      "        img_label = int(label[index-1])\n",
      "        train_label.append(img_label)\n",
      "        train_img.append(train_list[i])\n",
      "img_s = pd.Series(train_img)\n",
      "label_s = pd.Series(train_label)\n",
      "df = pd.DataFrame()\n",
      "df['img'] = img_s\n",
      "df['label'] = label_s\n",
      "path = os.path.join(train_path, 'dataset.csv')\n",
      "df.to_csv(path, index=None, header=None)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 19
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "val_list = os.listdir(val_path)\n",
      "val_label = []\n",
      "val_img = []\n",
      "num = len(val_list)\n",
      "for i in range(num):\n",
      "    prefix, type_ = os.path.splitext(val_list[i])\n",
      "    if type_ == \".jpg\":\n",
      "        index = int(prefix)\n",
      "        img_label = int(label[index-1])\n",
      "        val_label.append(img_label)\n",
      "        val_img.append(val_list[i])\n",
      "img_s = pd.Series(val_img)\n",
      "label_s = pd.Series(val_label)\n",
      "df = pd.DataFrame()\n",
      "df['img'] = img_s\n",
      "df['label'] = label_s\n",
      "path = os.path.join(val_path, 'dataset.csv')\n",
      "df.to_csv(path, index=None, header=None)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 18
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "a = pd.read_csv(path)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 22
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "test_path = r\"/media/root/515e7d3a-49ac-40be-ba58-fef9702d123c/work_record/digit_recognizer/digit-recognizer/digit-recognizer/1216/digit/test\"\n",
      "test_list = os.listdir(test_path)\n",
      "len1 = len(test_list)\n",
      "imgs_list = []\n",
      "label_list = [i+1 for i in range(len1)]\n",
      "for i in range(len1-1):\n",
      "    file_name = str(i+1)+\".jpg\"\n",
      "    imgs_list.append(file_name)\n",
      "imgs_s = pd.Series(imgs_list)\n",
      "label_s = pd.Series(label_list)\n",
      "df = pd.DataFrame()\n",
      "df['imgs'] = imgs_s\n",
      "df['label'] = label_s\n",
      "df.to_csv(test_path+'/dataset.csv', index=None, header=None)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 31
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "file_ = os.path.join(test_path, 'dataset.csv')\n",
      "file1 = pd.read_csv(file_, header=None)\n",
      "file1.shape[0]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 32,
       "text": [
        "28000"
       ]
      }
     ],
     "prompt_number": 32
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "file1"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-width:1500px;overflow:auto;\">\n",
        "<style scoped>\n",
        "    .dataframe tbody tr th:only-of-type {\n",
        "        vertical-align: middle;\n",
        "    }\n",
        "\n",
        "    .dataframe tbody tr th {\n",
        "        vertical-align: top;\n",
        "    }\n",
        "\n",
        "    .dataframe thead th {\n",
        "        text-align: right;\n",
        "    }\n",
        "</style>\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr style=\"text-align: right;\">\n",
        "      <th></th>\n",
        "      <th>0</th>\n",
        "      <th>1</th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0</th>\n",
        "      <td>1.jpg</td>\n",
        "      <td>1</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>1</th>\n",
        "      <td>2.jpg</td>\n",
        "      <td>2</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>2</th>\n",
        "      <td>3.jpg</td>\n",
        "      <td>3</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>3</th>\n",
        "      <td>4.jpg</td>\n",
        "      <td>4</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>4</th>\n",
        "      <td>5.jpg</td>\n",
        "      <td>5</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>5</th>\n",
        "      <td>6.jpg</td>\n",
        "      <td>6</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>6</th>\n",
        "      <td>7.jpg</td>\n",
        "      <td>7</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>7</th>\n",
        "      <td>8.jpg</td>\n",
        "      <td>8</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>8</th>\n",
        "      <td>9.jpg</td>\n",
        "      <td>9</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>9</th>\n",
        "      <td>10.jpg</td>\n",
        "      <td>10</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>10</th>\n",
        "      <td>11.jpg</td>\n",
        "      <td>11</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>11</th>\n",
        "      <td>12.jpg</td>\n",
        "      <td>12</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>12</th>\n",
        "      <td>13.jpg</td>\n",
        "      <td>13</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>13</th>\n",
        "      <td>14.jpg</td>\n",
        "      <td>14</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>14</th>\n",
        "      <td>15.jpg</td>\n",
        "      <td>15</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>15</th>\n",
        "      <td>16.jpg</td>\n",
        "      <td>16</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>16</th>\n",
        "      <td>17.jpg</td>\n",
        "      <td>17</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>17</th>\n",
        "      <td>18.jpg</td>\n",
        "      <td>18</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>18</th>\n",
        "      <td>19.jpg</td>\n",
        "      <td>19</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>19</th>\n",
        "      <td>20.jpg</td>\n",
        "      <td>20</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>20</th>\n",
        "      <td>21.jpg</td>\n",
        "      <td>21</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>21</th>\n",
        "      <td>22.jpg</td>\n",
        "      <td>22</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>22</th>\n",
        "      <td>23.jpg</td>\n",
        "      <td>23</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>23</th>\n",
        "      <td>24.jpg</td>\n",
        "      <td>24</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>24</th>\n",
        "      <td>25.jpg</td>\n",
        "      <td>25</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>25</th>\n",
        "      <td>26.jpg</td>\n",
        "      <td>26</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>26</th>\n",
        "      <td>27.jpg</td>\n",
        "      <td>27</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27</th>\n",
        "      <td>28.jpg</td>\n",
        "      <td>28</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>28</th>\n",
        "      <td>29.jpg</td>\n",
        "      <td>29</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>29</th>\n",
        "      <td>30.jpg</td>\n",
        "      <td>30</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>...</th>\n",
        "      <td>...</td>\n",
        "      <td>...</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27970</th>\n",
        "      <td>27971.jpg</td>\n",
        "      <td>27971</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27971</th>\n",
        "      <td>27972.jpg</td>\n",
        "      <td>27972</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27972</th>\n",
        "      <td>27973.jpg</td>\n",
        "      <td>27973</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27973</th>\n",
        "      <td>27974.jpg</td>\n",
        "      <td>27974</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27974</th>\n",
        "      <td>27975.jpg</td>\n",
        "      <td>27975</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27975</th>\n",
        "      <td>27976.jpg</td>\n",
        "      <td>27976</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27976</th>\n",
        "      <td>27977.jpg</td>\n",
        "      <td>27977</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27977</th>\n",
        "      <td>27978.jpg</td>\n",
        "      <td>27978</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27978</th>\n",
        "      <td>27979.jpg</td>\n",
        "      <td>27979</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27979</th>\n",
        "      <td>27980.jpg</td>\n",
        "      <td>27980</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27980</th>\n",
        "      <td>27981.jpg</td>\n",
        "      <td>27981</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27981</th>\n",
        "      <td>27982.jpg</td>\n",
        "      <td>27982</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27982</th>\n",
        "      <td>27983.jpg</td>\n",
        "      <td>27983</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27983</th>\n",
        "      <td>27984.jpg</td>\n",
        "      <td>27984</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27984</th>\n",
        "      <td>27985.jpg</td>\n",
        "      <td>27985</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27985</th>\n",
        "      <td>27986.jpg</td>\n",
        "      <td>27986</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27986</th>\n",
        "      <td>27987.jpg</td>\n",
        "      <td>27987</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27987</th>\n",
        "      <td>27988.jpg</td>\n",
        "      <td>27988</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27988</th>\n",
        "      <td>27989.jpg</td>\n",
        "      <td>27989</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27989</th>\n",
        "      <td>27990.jpg</td>\n",
        "      <td>27990</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27990</th>\n",
        "      <td>27991.jpg</td>\n",
        "      <td>27991</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27991</th>\n",
        "      <td>27992.jpg</td>\n",
        "      <td>27992</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27992</th>\n",
        "      <td>27993.jpg</td>\n",
        "      <td>27993</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27993</th>\n",
        "      <td>27994.jpg</td>\n",
        "      <td>27994</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27994</th>\n",
        "      <td>27995.jpg</td>\n",
        "      <td>27995</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27995</th>\n",
        "      <td>27996.jpg</td>\n",
        "      <td>27996</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27996</th>\n",
        "      <td>27997.jpg</td>\n",
        "      <td>27997</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27997</th>\n",
        "      <td>27998.jpg</td>\n",
        "      <td>27998</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27998</th>\n",
        "      <td>27999.jpg</td>\n",
        "      <td>27999</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27999</th>\n",
        "      <td>28000.jpg</td>\n",
        "      <td>28000</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "<p>28000 rows \u00d7 2 columns</p>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 33,
       "text": [
        "               0      1\n",
        "0          1.jpg      1\n",
        "1          2.jpg      2\n",
        "2          3.jpg      3\n",
        "3          4.jpg      4\n",
        "4          5.jpg      5\n",
        "5          6.jpg      6\n",
        "6          7.jpg      7\n",
        "7          8.jpg      8\n",
        "8          9.jpg      9\n",
        "9         10.jpg     10\n",
        "10        11.jpg     11\n",
        "11        12.jpg     12\n",
        "12        13.jpg     13\n",
        "13        14.jpg     14\n",
        "14        15.jpg     15\n",
        "15        16.jpg     16\n",
        "16        17.jpg     17\n",
        "17        18.jpg     18\n",
        "18        19.jpg     19\n",
        "19        20.jpg     20\n",
        "20        21.jpg     21\n",
        "21        22.jpg     22\n",
        "22        23.jpg     23\n",
        "23        24.jpg     24\n",
        "24        25.jpg     25\n",
        "25        26.jpg     26\n",
        "26        27.jpg     27\n",
        "27        28.jpg     28\n",
        "28        29.jpg     29\n",
        "29        30.jpg     30\n",
        "...          ...    ...\n",
        "27970  27971.jpg  27971\n",
        "27971  27972.jpg  27972\n",
        "27972  27973.jpg  27973\n",
        "27973  27974.jpg  27974\n",
        "27974  27975.jpg  27975\n",
        "27975  27976.jpg  27976\n",
        "27976  27977.jpg  27977\n",
        "27977  27978.jpg  27978\n",
        "27978  27979.jpg  27979\n",
        "27979  27980.jpg  27980\n",
        "27980  27981.jpg  27981\n",
        "27981  27982.jpg  27982\n",
        "27982  27983.jpg  27983\n",
        "27983  27984.jpg  27984\n",
        "27984  27985.jpg  27985\n",
        "27985  27986.jpg  27986\n",
        "27986  27987.jpg  27987\n",
        "27987  27988.jpg  27988\n",
        "27988  27989.jpg  27989\n",
        "27989  27990.jpg  27990\n",
        "27990  27991.jpg  27991\n",
        "27991  27992.jpg  27992\n",
        "27992  27993.jpg  27993\n",
        "27993  27994.jpg  27994\n",
        "27994  27995.jpg  27995\n",
        "27995  27996.jpg  27996\n",
        "27996  27997.jpg  27997\n",
        "27997  27998.jpg  27998\n",
        "27998  27999.jpg  27999\n",
        "27999  28000.jpg  28000\n",
        "\n",
        "[28000 rows x 2 columns]"
       ]
      }
     ],
     "prompt_number": 33
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}